<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot 文件上传</title>
    <link rel="stylesheet" href="/css/styles.css">
</head>
<body>
<div class="container">
    <h1>Spring Boot 文件上传</h1>

    <!-- 消息区域 -->
    <div th:if="${message}" class="alert success">
        <span th:text="${message}"></span>
    </div>

    <div th:if="${error}" class="alert error">
        <span th:text="${error}"></span>
    </div>

    <!-- 上传表单 -->
    <form action="/upload" method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label for="file">选择文件：</label>
            <input type="file" name="file" id="file" required>
            <p class="help-text">最大文件大小: <span th:text="${@environment.getProperty('file.max-size')}"></span></p>
        </div>
        <button type="submit" class="btn">上传文件</button>
    </form>

    <!-- 文件列表 -->
    <div class="file-list" th:if="${not #lists.isEmpty(fileList)}">
        <h2>上传的文件</h2>
        <table>
            <thead>
            <tr>
                <th>文件名</th>
                <th>大小</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <!-- 修改这里：使用文件名而不是File对象 -->
            <tr th:each="file : ${fileList}">
                <td th:text="${file.name}"></td>
                <td th:text="${file.size}"></td>
                <td>
                    <a th:href="@{/view/{name}(name=${file.name})}" class="btn small">查看</a>
                    <a th:href="@{/download/{name}(name=${file.name})}" class="btn small primary">下载</a>
                </td>
            </tr>
            </tbody>
        </table>
    </div>

    <div th:if="${#lists.isEmpty(fileList)}" class="empty-message">
        没有文件，请上传文件
    </div>
</div>
</body>
</html>